package com.xuedongzhilian.controller;

import com.xuedongzhilian.dto.Result;
import com.xuedongzhilian.service.IWechatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 微信公众号控制器
 * </p>
 *
 * @author 学动智联团队
 * @since 2025-10-14
 */
@Slf4j
@RestController
@RequestMapping("/wechat")
public class WechatController {

    @Resource
    private IWechatService wechatService;

    /**
     * 微信公众号消息接收接口
     */
    @PostMapping("/message")
    public Result receiveWechatMessage(@RequestBody Object message) {
        return wechatService.handleWechatMessage(message);
    }

    /**
     * 微信公众号验证接口
     */
    @GetMapping("/message")
    public String verifyWechatSignature(@RequestParam String signature,
                                       @RequestParam String timestamp,
                                       @RequestParam String nonce,
                                       @RequestParam String echostr) {
        // TODO 实现微信公众号验证逻辑
        // 这里只是示例，实际需要验证微信签名
        return echostr;
    }

    /**
     * 发送打卡提醒模板消息
     */
    @PostMapping("/send-checkin-reminder")
    public Result sendCheckinReminder(@RequestParam Long userId) {
        // 打卡提醒模板ID
        String templateId = "CHECKIN_REMINDER_TEMPLATE";
        // 消息数据
        Object data = new Object(); // 实际应该构造具体的消息数据
        return wechatService.sendTemplateMessage(userId, templateId, data);
    }

    /**
     * 发送成就解锁通知模板消息
     */
    @PostMapping("/send-achievement-notification")
    public Result sendAchievementNotification(@RequestParam Long userId) {
        // 成就解锁通知模板ID
        String templateId = "ACHIEVEMENT_NOTIFICATION_TEMPLATE";
        // 消息数据
        Object data = new Object(); // 实际应该构造具体的消息数据
        return wechatService.sendTemplateMessage(userId, templateId, data);
    }
}